package com.mdnote.practice.sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/11/16 20:56
 * @Email rhythm_2019@163.com
 * @Description  406. 根据身高重建队列
 */
public class LeetCode406 {

    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (p1, p2) -> {
            if (p1[0] != p2[0]) {
                return p2[0] - p1[0];
            } else {
                return p1[1] - p2[1];
            }
        });

        List<int[]> ans = new ArrayList<>();

        for (int i = 0; i < people.length; i++) {
            ans.add(people[i][1], people[i]);
        }

        return ans.toArray(new int[0][0]);
    }
}
